package com.zhuzi.controller;

import com.zhuzi.dto.PersonDTO;
import com.zhuzi.utils.IMBConsts;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/sendMessage")
public class SendController {
    @Autowired
    private JmsTemplate jmsTemplate;

    @Value("${ibm.mq.queueSend}")
    private String queueSend;

    @GetMapping("send")
    //@PostConstruct
    public ResponseEntity sendMessage(String message) {

        for (int i = 0; i < 5; i++) {
            jmsTemplate.convertAndSend(queueSend, i + "Hello World!" + message);
        }

        return ResponseEntity.ok().build();
    }

    @GetMapping("send/{name}")
    public ResponseEntity sendMessageDTO(@PathVariable String name) {
        PersonDTO personDTO = new PersonDTO().setName(name);
        //jmsTemplate.convertAndSend("QRSdcHhhTZBQ", personDTO);
        jmsTemplate.convertAndSend("QRSdcHhhTZBQ", "Hello World!" + name);
        log.info("发送消息[{}]", name);
        return ResponseEntity.ok().build();
    }
}
